package com.wude.guild.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.wude.guild.fragment.GameDetCommentFragment;
import com.wude.guild.fragment.GameDetGiftFragment;
import com.wude.guild.fragment.GameDetIntroductionFragment;
import com.wude.guild.fragment.GameDetKaifuFragment;

/**
 * 游戏详情页面FragmentAdapter
 * Created by Administrator on 2017/3/20.
 */

public class GameDetFragmentAdapter extends FragmentStatePagerAdapter {

    private final String anInt;
    private GameDetIntroductionFragment introductionFragment;
    private GameDetGiftFragment gameDetGiftFragment;
    private GameDetKaifuFragment gameDetKaifuFragment;
    private GameDetCommentFragment gameDetCommentFragment;

    public GameDetFragmentAdapter(FragmentManager fm, String id) {
        super(fm);
        anInt = id;
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            if (introductionFragment == null) {
                introductionFragment = new GameDetIntroductionFragment();          //简介
                Bundle bundle = new Bundle();
                bundle.putString("key", anInt);
                introductionFragment.setArguments(bundle);
                return introductionFragment;
            } else {
                return introductionFragment;
            }
        } else if (position == 1) {
            if (gameDetGiftFragment == null) {
                gameDetGiftFragment = new GameDetGiftFragment();                    //礼包
                Bundle bundle = new Bundle();
                bundle.putString("key", anInt);
                gameDetGiftFragment.setArguments(bundle);
                return gameDetGiftFragment;
            } else {
                return gameDetGiftFragment;
            }
        } else if (position == 2) {
            if (gameDetKaifuFragment == null) {
                gameDetKaifuFragment = new GameDetKaifuFragment();                  //开服
                Bundle bundle = new Bundle();
                bundle.putString("key", anInt);
                gameDetKaifuFragment.setArguments(bundle);
                return gameDetKaifuFragment;
            } else {
                return gameDetKaifuFragment;
            }
        } else if (position == 3) {
            if (gameDetCommentFragment == null) {
                gameDetCommentFragment = new GameDetCommentFragment();                   //评论
                Bundle bundle = new Bundle();
                bundle.putString("key", anInt);
                gameDetCommentFragment.setArguments(bundle);
                return gameDetCommentFragment;
            } else {
                return gameDetCommentFragment;
            }
        } else {
            return null;
        }
    }

    @Override
    public int getCount() {
        return 4;
    }
}
